<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2023-11-06 10:26:01
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description:   :gridOps="gridOptions" inventory
-->
<template>
  <sc-VxeTable
    ref="xGrid"
    :gridEvts="gridEvents"
    :tablecode="'purchase_complaint'"
    :url="api.purchase.complaint.list"
    :children="{
      tablecode: 'purchase_complaint_details',
      url: api.purchase.complaint.details,
      key: 'main_id',
    }"
  >
  </sc-VxeTable>
  <storage-dig
    v-if="dialog.storage"
    ref="storage"
    @success="handleSuccess"
    @closed="handleSuccess"
  ></storage-dig>
  <save-dig
    v-if="dialog.save"
    ref="saveDialog"
    @success="handleSuccess"
    @closed="dialog.save = false"
  ></save-dig>
</template>
<script>
export default {
  name: "purchase_complaint",
};
</script>
<script setup>
import { ref, nextTick } from "vue";
import storageDig from "./storage";
import saveDig from "./save";
import api from "@/api";
const dialog = ref({
  storage: false,
  save: false,
});

const xGrid = ref({});
const saveDialog = ref({});
const storage = ref({});
const handleSuccess = () => {
  xGrid.value.refresh();
};
const edit = row => {
  dialog.value.save = true;
  nextTick(() => {
    saveDialog.value.setData(row);
    saveDialog.value.open("edit");
  });
};
const gridEvents = {
  cellDblclick: function ({ row }) {
    edit(row);
  },
  add: function () {
    dialog.value.storage = true;
    nextTick(() => {
      storage.value.open().setHandle(handleSuccess);
    });
  },
  edit: function ({ button }) {
    edit(button.selectRecords[0]);
  },
};
</script>
